﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Eoffice.Models;

namespace Eoffice.Controllers
{
    public class DenxulyController : Controller
    {
        private EofficeDb db = new EofficeDb();

        //
        // GET: /Denxuly/

        public ActionResult Index()
        {
            var denxulies = db.DENXULies.Include(d => d.CVDEN).Include(d => d.NV);
            return View(denxulies.ToList());
        }

        //
        // GET: /Denxuly/Details/5

        public ActionResult Details(int id = 0)
        {
            DENXULY denxuly = db.DENXULies.Find(id);
            if (denxuly == null)
            {
                return HttpNotFound();
            }
            return View(denxuly);
        }

        //
        // GET: /Denxuly/Create

        public ActionResult Create()
        {
            ViewBag.STTCV = new SelectList(db.CVDENs, "STTCV", "STTCV");
            ViewBag.MSNV = new SelectList(db.NVs, "MSNV", "HOTENNV");
            return View();
        }

        //
        // POST: /Denxuly/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(DENXULY denxuly)
        {
            if (ModelState.IsValid)
            {
                db.DENXULies.Add(denxuly);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.STTCV = new SelectList(db.CVDENs, "STTCV", "STTCV", denxuly.STTCV);
            ViewBag.MSNV = new SelectList(db.NVs, "MSNV", "HOTENNV", denxuly.MSNV);
            return View(denxuly);
        }

        //
        // GET: /Denxuly/Edit/5

        public ActionResult Edit(int id = 0)
        {
            DENXULY denxuly = db.DENXULies.Find(id);
            if (denxuly == null)
            {
                return HttpNotFound();
            }
            ViewBag.STTCV = new SelectList(db.CVDENs, "STTCV", "STTCV", denxuly.STTCV);
            ViewBag.MSNV = new SelectList(db.NVs, "MSNV", "HOTENNV", denxuly.MSNV);
            return View(denxuly);
        }

        //
        // POST: /Denxuly/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(DENXULY denxuly)
        {
            if (ModelState.IsValid)
            {
                db.Entry(denxuly).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.STTCV = new SelectList(db.CVDENs, "STTCV", "STTCV", denxuly.STTCV);
            ViewBag.MSNV = new SelectList(db.NVs, "MSNV", "HOTENNV", denxuly.MSNV);
            return View(denxuly);
        }

        //
        // GET: /Denxuly/Delete/5

        public ActionResult Delete(int id = 0)
        {
            DENXULY denxuly = db.DENXULies.Find(id);
            if (denxuly == null)
            {
                return HttpNotFound();
            }
            return View(denxuly);
        }

        //
        // POST: /Denxuly/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            DENXULY denxuly = db.DENXULies.Find(id);
            db.DENXULies.Remove(denxuly);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}